<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <form action="" method="post" id="stuInfo">
            <table border="1" cellspacing="0" cellpadding="10">
                <tr>
                    <th></th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>家庭住址</th>
                </tr>
                <tr>
                    <th><input type="checkbox" name=""  value="" /></th>
                    <th >张三</th>
                    <th class="sex">女</th>
                    <th>19</th>
                    <th>福建龙岩</th>
                </tr>
                <tr>
                    <th><input type="checkbox" name=""  value="" /></th>
                    <th>张三</th>
                    <th class="sex">男</th>
                    <th>19</th>
                    <th>福建龙岩</th>
                </tr>
                <tr>
                    <th><input type="checkbox" name=""  value="" /></th>
                    <th>张三</th>
                    <th class="sex">男</th>
                    <th>19</th>
                    <th>福建龙岩</th>
                </tr>
                <tr>
                    <th><input type="checkbox" name=""  value="" /></th>
                    <th>张三</th>
                    <th class="sex">女</th>
                    <th>19</th>
                    <th>福建龙岩</th>
                </tr>
                <tr>
                    <th><input type="checkbox" name=""  value="" /></th>
                    <th>张三</th>
                    <th class="sex">男</th>
                    <th>19</th>
                    <th>福建龙岩</th>
                </tr>
                
            </table>
        </form>
        <input type="checkbox" name="" id="allCheck" value="" onclick="doAction()"/>全选
        <input type="checkbox" name="" id="allCheckByWoman" value="" onclick="doActionSex()"/>全选女
        <input type="checkbox" name="" id = "allCheckByMan" value="" onclick="doActionMan()"/>全选男
    </body>
    
    <script type="text/javascript">
        function doAction(){
            var stuInfo = document.getElementById('stuInfo');
            var checkboxAll = stuInfo.getElementsByTagName('input')
            var checkById = document.getElementById('allCheck').checked;
            // console.log(checkById);
            for(var i = 0 ; i < checkboxAll.length ; i++){
                checkboxAll[i].checked = checkById;
            }
        }
        
        function doActionMan(){
            var stuInfo = document.getElementById('stuInfo');
            var checkboxAll = stuInfo.getElementsByTagName('input');
            var sex = stuInfo.getElementsByClassName('sex');
            var checkById = document.getElementById('allCheckByMan').checked;
            console.log(checkById);
            for(var i = 0 ; i<sex.length ; i++){
                if(sex[i].innerText == '男'){
                    checkboxAll[i].checked = checkById;
                    console.log(sex[i].innerText);
                    }
                }
            }
        
        function doActionSex(){
            var stuInfo = document.getElementById('stuInfo');
            var checkboxAll = stuInfo.getElementsByTagName('input');
            var sex = stuInfo.getElementsByClassName('sex');
            var checkById = document.getElementById('allCheckByWoman').checked;
            console.log(checkById);
            
            for(var i = 0 ; i<sex.length ; i++){
                if(sex[i].innerText == '女'){
                    checkboxAll[i].checked = checkById;
                    console.log(sex[i].innerText);
                    }
                }
            }
    </script>
</html>
